﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Template.Master"
    Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript" src="/Content/Widget/jquery.fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
    <script type="text/javascript" src="/Content/Widget/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <link rel="stylesheet" type="text/css" href="/Content/Widget/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.css"
        media="screen" />
    <script type="text/javascript">

        function eidtProduct(id) {
            window.top.addTab("", "修改产品", '<%=Url.Action("Edit") %>' + '?id=' + id, true);
        }
        $(function () {
            var categoryTypeData;
            $.ajax({
                url: '<%=Url.Action("GetProductComboBoxJson","Category") %>',
                dataType: 'json',
                type: 'post',
                async: false,
                success: function (data) {
                    categoryTypeData = data;
                }
            });
            var currentNoid = null;
            var p = $('body').layout('panel', 'west').panel({
                onCollapse: function () {
                }
            });
            var lastIndex;
            var grid = $('#tt').datagrid({
                width: 'auto',
                height: '400',
                nowrap: false,
                striped: true,
                remoteSort: false,
                collapsible: true,
                fitColumns: true,
                url: '<%=Url.Action("GetListJson") %>',
                sortName: 'Sort',
                sortOrder: 'asc',
                idField: 'Id',
                pagination: true,
                onLoadSuccess: function () {
                    $("a[name=fancybox-product]").fancybox({
                        'overlayShow': false,
                        'transitionIn': 'elastic',
                        'transitionOut': 'elastic',
                        hideOnOverlayClick: true,
                        hideOnContentClick: true

                    });

                },
                columns: [[
                    { field: 'Id', checkbox: true },
                // { field: 'Code', title: '编号', width: 80, align: 'center' },
                    {field: 'Name', title: '名称', width: 120, align: 'center' },
                    { field: 'Model', title: '型号', width: 120, align: 'center' },
                //    { field: 'NameEn', title: '名称(EN)', width: 120, align: 'center' },
                //                      { field: 'CategoryId', title: '产品类型', width: 80, align: 'center', formatter: function (value, rec) {
                //                          for (var i = 0; i < categoryTypeData.length; i++) {
                //                              if (categoryTypeData[i].id == value) return categoryTypeData[i].text;
                //                          }
                //                          return "";

                //                      }
                //                      }
                //                      ,
                //                   	{ field: 'IsRecommend', title: '推荐', width: 40, align: 'center', formatter: function (value, rec) {

                //                   	    return value ? '是' : '否';
                //                   	}
                //                   	},
                     {field: 'NormalImage', title: '图片', width: 40, align: 'center', formatter: function (value, rowData, rec) {
                         return '<a name="fancybox-product" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.NormalImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Image/easyicon_cn_32.png" /></a>'; ;
                     }
                 },
                        { field: 'SmallImage', title: '图片(小)', width: 40, align: 'center', formatter: function (value, rowData, rec) {
                            return '<a name="fancybox-product" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.SmallImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Image/easyicon_cn_32.png" /></a>'; ;
                        }
                        },
                    { field: 'OptEdit', title: '修改', width: 80, align: 'center', formatter: function (value, rowData, rec) {
                        return '<span style="color:red" class="jqeasyui-datagrid-edit" onclick="eidtProduct(\'' + rowData.Id + '\')" value=' + rowData.Id + '>修改</span>'; ;
                    }
                    }
                ]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        window.top.addTab("", "添加产品", '<%=Url.Action("Create") %>');

                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var rows = $('#tt').datagrid('getSelections');
                        if (!rows || rows.length == 0) {
                            $.messager.alert('提示', '请选择要删除的数据');
                            return;
                        }
                        var parm;
                        $.each(rows, function (i, n) {
                            if (i == 0) {
                                parm = "id=" + n.Id;
                            }
                            else {
                                parm += "&id=" + n.Id;
                            }
                        });
                        $.messager.confirm('提示', '是否删除这些数据?', function (r) {
                            if (!r) {
                                return;
                            }
                            $.ajax({
                                type: "POST",
                                url: '<%=Url.Action("Delete") %>',
                                data: parm,
                                success: function (msg) {
                                    if (msg.state) {
                                        $.messager.alert('提示', '删除成功！', "info", function () {
                                            $('#tt').datagrid("reload");
                                        });
                                    }
                                },
                                error: function () {
                                    $.messager.alert('错误', '删除失败！', "error");
                                }
                            });
                        });
                    }
                }, '-', {
                    text: '全部',
                    iconCls: 'icon-search',
                    handler: function () {
                        clickTree("");
                    }
                }],
                onBeforeLoad: function () {
                    $(this).datagrid('rejectChanges');
                },
                onClickRow: function (rowIndex) {
                    $(this).datagrid("unselectRow", rowIndex);

                }
            });
            //            var tree = $('#tree').tree({
            //                checkbox: false,
            //                methord: 'get',
            //                url: '<%=Url.Action("GetProductTreeJson","Category") %>?&ran=' + Math.random(),
            //                onBeforeExpand: function (node, param) {
            //                    //alert(node.id);
            //                    // $('#tree').tree('options').url = "GetClassJsonByPid.ashx?pid=" + node.id; // change the url                       
            //                },
            //                onClick: function (node) {
            //                    clickTree(node.id);
            //                }
            //            });
            function clickTree(nodeid) {
                grid.datagrid({ url: '<%=Url.Action("GetListJson","Product") %>?categoryId=' + nodeid });
                grid.datagrid('clearSelections');
            }
            $('#btn-search-product').click(function () {
                grid.datagrid({ url: '<%=Url.Action("GetListJson","Product") %>?' + $('#form-search').serialize() });
                grid.datagrid('clearSelections');

            });
            $('#cc').combobox({
                url: '<%=Url.Action("GetProductComboBoxJson","Category") %>',
                valueField: 'id',
                textField: 'text'
            });

            $('#search-product').panel({
                width: 'auto',
                height: 'auto',
                title: '检索产品'

            });

        });


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%--   <div region="west" split="true" title="产品类型" style="width: 180px;" id="west">
        <ul id="tree">
        </ul>
    </div>--%>
    <div region="center" style="width: auto; height: 100%; padding: 1px; position: relative;
        overflow-y: auto">
        <div id="search-product" title="检索产品">
            <form id="form-search">
            <ul style="display: block; border: 0px solid #C4E7FB; height: 30px; margin: 4px 10px;
                padding: 10px 2px; vertical-align: middle;">
                <%--<li style="padding: 0px; list-style-type: none; display: inline">
                    <label style="display: block; display: inline-block; zoom: 1; _display: inline; vertical-align: middle;
                        width: 100px; text-align: right; padding: 0px 5px 0px 0px;">
                        产品分类:</label>
                    <select id="cc" name="CategoryId">
                    </select>
                </li>--%>
                <li style="padding: 0px; list-style-type: none; display: inline">
                    <label style="display: block; display: inline-block; zoom: 1; _display: inline; vertical-align: middle;
                        width: 100px; text-align: right; padding: 0px 5px 0px 0px;">
                        名称:</label>
                    <input title="" type="text" name="Name" />
                </li>
                <li style="padding: 0px; list-style-type: none; display: inline">
                    <input title="" type="button" id="btn-search-product" value="搜索" />
                </li>
            </ul>
            </form>
        </div>
        <table id="tt" style="height: auto;" title="产品列表" iconcls="icon-edit">
        </table>
    </div>
</asp:Content>
